<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>教师档案</title>
</head>

<body>
<?php
 session_start();

 include("../main/function.php");
 include("../main/ShowPage.class.php");
 include("../main/islogin.php");
 $db=new Db();
 $type=$_SESSION['type'];
 echo "111";
//用户搜索
	$swhere=' and 1=1 ';
	$swhere2=' and 1=1 ';
	if($_SESSION['area_id']){
	   $area_id=$_SESSION['area_id'];
	}
	if($_POST['search'] or $_POST['submit2']){
		$search_name=$_POST['search_name'];
		$search_sex=$_POST['search_sex'];
		$search_idcard=$_POST['search_idcard'];
		$search_area=$_POST['search_area'];
		//拼装搜索条件
		if($search_name){
		   $swhere.=" and a.name like '%".$search_name."%'";	
		}
		if($search_sex){
		   $swhere.=" and a.sex='".$search_sex."'";
		}
		if($search_idcard){
		   $swhere.=" and a.idcard;='".$search_idcard."'";
		}
		if($search_area){
		   $swhere.=" and a.area='".$search_area."'";
		}
	}
	//保存搜索条件
	//$_SESSION['swhere']=$swhere;
	//$_SESSION['swhere2']=$swhere2;
	
/*处理导出数据*/
		$sql="SELECT a.name as Name ,a.*,b.*,c.* FROM teacher a ,area b,education c where a.area=b.id and a.education=c.id $swhere order by a.id ";
		//$sql="select e.*,f.name as areafname from (SELECT a.*,b.fid as afid ,b.id as aid,b.name as areaname FROM teacher a ,area b,education c,company d where a.area=b.id and a.education=c.id and a.company=d.id  $swhere ) e,area f where e.afid=f.id $swhere2 ";
		//exit($sql);
		$teacher=$db->fetchRows($sql);		
		
		//输出的文件类型为excel
		header("Content-type:text/html;charset=UTF-8");
		header("Content-type:application/vnd.ms-excel");
		//提示下载
		header("Content-Disposition:attachement;filename=TeacherReport_".date("Ymd").".xls");
		//$ReportArr = array(    array(1,2,3,4,5),
        //                 array('A','B','C','D','E'),
         //               array('up','down','left','right','center'),
        //                array('欢','迎','光','临','教','师','档','案','系','统')
        //            );
		
		//报表数据
		$ReportArr = array( );
		//填充数据
		$ReportArr[]=array("姓名","性别","出生日期","身份证号码","政治面貌","地区","所在单位","手机","固话","电子邮箱","学历","学位","毕业时间","毕业院校","参加工作时间","职务","职称","职称评定时间","现任职","培训经历","获奖情况");
		foreach($teacher as $k=>$v){
			$ReportArr[]=array($v['Name'],$v['sex'],$v['birth'],$v['idcard'],$v['partisan'],$v['areafname'].$v['areaname'],$v['company'],$v['phone'],$v['tel'],$v['email'],$v['education'],$v['degree'],$v['graduation_time'],$v['graduation_school'],$v['work_time'],$v['post'],$v['title'],$v['title_time'],$v['office'],$v['train'],$v['award']);
		}
		//
		$ReportContent = '';
		$num1 = count($ReportArr);
		for($i=0;$i<$num1;$i++){
			$num2 = count($ReportArr[$i]);
			for($j=0;$j<$num2;$j++){
				//ecxel都是一格一格的，用\t将每一行的数据连接起来
				$ReportContent .= ''.$ReportArr[$i][$j].' '."\t";
			}
			//最后换行
			$ReportContent .= "<br/>"; 
		}
		//用的utf-8 最后转换一个编码为gb
		$ReportContent = mb_convert_encoding($ReportContent,"utf-8","utf-8");
		//输出即提示下载
		echo $ReportContent;
		//sleep(2);  //程序暂停10s
		//header('location:list_teacher.php');
		exit();
?>
</body>
</html>
